﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YmtAuth.Domain.Model.BlacklistUser;

namespace YmtAuth.Domain.Model.Safe
{
    public class SafeCfgKey
    {
        public const string LoginSafe_Pc_Open = "LoginSafe_Pc_Open";

        //用户登录，收集其常用IP区域
        public const string LoginSafe_Pc_GetUserIpArea = "LoginSafe_Pc_GetUserIpArea";

        /// <summary>
        /// token认证/获取用户token，收集其常用IP区域
        /// </summary>
        public const string LoginSafe_AuthToken_GetUserIpArea = "LoginSafe_AuthToken_GetUserIpArea";

        public const string LoginSafe_PcLoginPas_Check = "LoginSafe_PcLoginPas_Check";
        public const string LoginSafe_PcLoginPas_ErrorAction = "LoginSafe_PcLoginPas_ErrorAction";
        public const string LoginSafe_PcLoginPas_CheckSpec = "LoginSafe_PcLoginPas_CheckSpec";

        /// <summary>
        /// [N:M] 最近N分钟登录密码错误次数超过M次，LoginId拉入黑名单; 如果M为-1，则跳过该验证
        /// </summary>
        public const string LoginSafe_LoginIdLimit_CheckSpec = "LoginSafe_LoginIdLimit_CheckSpec";

        public const string LoginSafe_PcIp_ExistsCheck = "LoginSafe_PcIp_ExistsCheck";
        [Obsolete]
        public const string LoginSafe_PcIp_NotExistsIdentityVerify = "LoginSafe_PcIp_NotExistsIdentityVerify";
        public const string LoginSafe_PcIp_AuthStatusCheck = "LoginSafe_PcIp_AuthStatusCheck";
        public const string LoginSafe_PcIp_AuthFailAction = "LoginSafe_PcIp_AuthFailAction";
        public const string LoginSafe_PcIp_AuthSuccessAction = "LoginSafe_PcIp_AuthSuccessAction";

        public const string LoginSafe_PcBlacklist_Check = "LoginSafe_PcBlacklist_Check";
        public const string LoginSafe_PcBlacklist_BlacklistAction = "LoginSafe_PcBlacklist_BlacklistAction";

        public const string LoginSafe_PcToken_Check = "LoginSafe_PcToken_Check";
        public const string LoginSafe_PcToken_LastAuthDay = "LoginSafe_PcToken_LastAuthDay";
        public const string LoginSafe_PcToken_GtLastDayAction = "LoginSafe_PcToken_GtLastDayAction";
        //2016.7.14
        [Obsolete]
        public const string LoginSafe_PcUserFirstLogin_AutoAuthSuccess = "LoginSafe_PcUserFirstLogin_AutoAuthSuccess";
        //////////////////////////////////////////////////////////////////////////////////////////////    
        public const string LoginSafe_App_Open = "LoginSafe_App_Open";

        public const string LoginSafe_AppLoginPas_Check = "LoginSafe_AppLoginPas_Check";
        public const string LoginSafe_AppLoginPas_ErrorAction = "LoginSafe_AppLoginPas_ErrorAction";
        public const string LoginSafe_AppLoginPas_CheckSpec = "LoginSafe_AppLoginPas_CheckSpec";

        public const string LoginSafe_AppDevice_ExistsCheck = "LoginSafe_AppDevice_ExistsCheck";
        public const string LoginSafe_AppDevice_NotExists = "LoginSafe_AppDevice_NotExists";

        public const string LoginSafe_AppDevice_StatusCheck = "LoginSafe_AppDevice_StatusCheck";
        public const string LoginSafe_AppDevice_AuthSuccessAction = "LoginSafe_AppDevice_AuthSuccessAction";
        public const string LoginSafe_AppDevice_AuthFailAction = "LoginSafe_AppDevice_AuthFailAction";

        public const string LoginSafe_AppClientId_ExistsCheck = "LoginSafe_AppClientId_ExistsCheck";
        public const string LoginSafe_AppClientIde_StatusCheck = "LoginSafe_AppClientIde_StatusCheck";
        public const string LoginSafe_AppClientId_AuthSuccessAction = "LoginSafe_AppClientId_AuthSuccessAction";
        public const string LoginSafe_AppClientId_AuthFailAction = "LoginSafe_AppClientId_AuthFailAction";

        public const string LoginSafe_AppBlacklist_Check = "LoginSafe_AppBlacklist_Check";
        public const string LoginSafe_AppBlacklist_BlacklistAction = "LoginSafe_AppBlacklist_BlacklistAction";

        public const string LoginSafe_AppToken_Check = "LoginSafe_AppToken_Check";
        public const string LoginSafe_AppToken_LastAuthDay = "LoginSafe_AppToken_LastAuthDay";
        public const string LoginSafe_AppToken_GtLastAuthDay = "LoginSafe_AppToken_GtLastAuthDay";
        public const string LoginSafe_AppIp_ExistsCheck = "LoginSafe_AppIp_ExistsCheck";
        //APP端用户IP区域
        public const string LoginSafe_AppIpUserToken_Check = "LoginSafe_AppIpUserToken_Check";
        public const string LoginSafe_AppIp_AuthStatusCheck = "LoginSafe_AppIp_AuthStatusCheck";

        public const string LoginSafe_AppIp_AuthFailAction = "LoginSafe_PcIp_AuthFailAction";
        public const string LoginSafe_AppIp_AuthSuccessAction = "LoginSafe_PcIp_AuthSuccessAction";

        public const string LoginSafe_AppIpBlacklist_Check = "LoginSafe_AppIpBlacklist_Check";
        public const string LoginSafe_AppIpBlacklist_BlacklistAction = "LoginSafe_AppIpBlacklist_BlacklistAction";
        //用户登录，收集其常用设备区域
        public const string LoginSafe_App_GetUserDevice = "LoginSafe_App_GetUserDevice";

        //PC端部分用户风控
        public const string LoginSafe_Partial_Mode = "LoginSafe_Partial_Mode";
        public const string LoginSafe_Partial_Range = "LoginSafe_Partial_Range";
        //APP端部分用户风控
        public const string LoginSafe_AppPartial_Mode = "LoginSafe_AppPartial_Mode";
        public const string LoginSafe_App_Partial_Range = "LoginSafe_AppPartial_Range";

        public const string LoginSafe_Check_List = "LoginSafe_Check_List";
        //2016.7.14
        public const string LoginSafe_AppUserFirstLogin_AutoAuthSuccess = "LoginSafe_AppUserFirstLogin_AutoAuthSuccess";


        public static string KeyFormart(string key, string source)
        {
            if (YmatouBlacklistUserSpecifications.IsSellerSource(source))
            {
                var keyArray = key.Split(new char[] { '_' });
                if (keyArray.Length < 3) return key;
                var newKey = string.Format("{0}_{1}_Seller{2}", keyArray[0], keyArray[1], keyArray[2]);
                return newKey;
            }
            return key;
        }

        public static string SellerKey(string key)
        {
            var keyArray = key.Split(new char[] { '_' });
            if (keyArray.Length < 3) return key;
            var newKey = string.Format("{0}_{1}_Seller{2}", keyArray[0], keyArray[1], keyArray[2]);
            return newKey;
        }
    }
}
